<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="./vue.js"></script>
    <style>
        .active {
            color: red;
        }
    </style>
</head>

<body>
    <div id="app">
        <button @click="name='one'" :class="{active:name=='one'}">one</button>
        <button @click="name='tow'" :class="{active:name=='tow'}">tow</button>
        <button @click="name='thre'" :class="{active:name=='thre'}">thre</button>
        <div>
            <keep-alive>
                <component :is="name"></component>
            </keep-alive>
        </div>
    </div>
    <script>
        Vue.component('one', {
            template: `
                <div>
                    one{{username}}
                </div>
         `,
         data(){
                return{
                    username:""
                }
            },
            created(){
                fetch("./1.json")
                    .then(res => res.json())
                    .then(res => {
                        console.log(res);
                        this.username = res.name
                    })
            }
        })
        Vue.component('tow', {
            template: `
                <div>
                    towwerwerwerwerwerwer
                </div>
         `,

        })
        Vue.component('thre', {
            template: `
                <div>
                    threweewrwe
                </div>
         `,
        })
        new Vue({
            el: "#app",
            data() {
                return {
                    name: "one"
                }
            }
        })
    </script>
</body>

</html>